#include "SceneNode.h"
#include "../BaseApplication.h"

mtBEGIN(SceneNode)
	mtBASE(ECS::Component);
mtEND

SceneNode::SceneNode() :
	_sceneNode(nullptr)
{

}

SceneNode::~SceneNode()
{

}

void SceneNode::setNodePosition(const Vector2& position)
{
	_sceneNode->setPosition(position.x, 0, position.y);
}

void SceneNode::setNodeRotation( float rotation )
{
	auto q = Ogre::Quaternion(Ogre::Radian(rotation), Ogre::Vector3::UNIT_Y);
	_sceneNode->setOrientation(q);
}

void SceneNode::setNodeScale(float scale)
{
	_sceneNode->setScale(scale, scale, scale);
}

//// SImple model

mtBEGIN(SimpleSceneNode)
	mtBASE(SceneNode);
	mtMETHOD(onStart);
mtEND

SimpleSceneNode::SimpleSceneNode()
{
	meshName = "ogrehead.mesh";
}

SimpleSceneNode::~SimpleSceneNode()
{

}

void SimpleSceneNode::onStart()
{
	Ogre::SceneManager* sceneManager = BaseApplication::getSceneManager();//Ogre::Root::getSingleton().getSceneManager(Ogre::ST_GENERIC);

	// Create an Entity
	Ogre::Entity* entity = sceneManager->createEntity(meshName.c_str());

	// Create a SceneNode and attach the Entity to it
	_sceneNode = sceneManager->getRootSceneNode()->createChildSceneNode();

	_sceneNode->attachObject(entity);
}
